
local Shapes = import('..data.physicsShapes')



local min_test = class('min_test',function()
	return display.newNode()
end)

function min_test:ctor()
	physicsShapes = Shapes:new()
	cc.GameObject.extend(self):addComponent("components.behavior.EventProtocol"):exportMethods()
	self:pos(100,100)
	local tmpNode = display.newNode():addTo(self)
	local bodys = {}

	--local frames = display.newFrames("min_jump_%03d.png", 0, 10)
	--local frames = display.newFrames("min_run_%03d.png", 0, 6)
	local frames = display.newFrames("min_die_%03d.png", 0, 6)
	self.sprites = {}
	local dx,dy = display.width/4,display.height/4
	local number = 1
	for row=1,4 do
		if number > #frames then break end
		for cos=1,4 do
			self.sprites[number] = cc.Sprite:createWithSpriteFrame(frames[number]):addTo(tmpNode)
			display.newSolidCircle(8,{color = cc.c4f(0.0,1,0.6,0.8)}):addTo(self.sprites[number])
			self.sprites[number]:pos(dx/2+(cos-1)*dx,dy/2+(row-1)*dy)
			number = number + 1
			if number > #frames then break end
		end
	end

	for i=1,#frames do
		--bodys[i] = cc.PhysicsBody:create()
		--bodys[i]:setContactTestBitmask(-1)
		--bodys[i]:addShape(physicsShapes.minrun.jump[i])
		--bodys[i]:addShape(physicsShapes.minrun.run[i])
		local shape = physicsShapes.minrun.die[i]
		if not shape then print(' not have shape ') 
		else
			printf(' shape tag = %d',shape:getTag()) 
			bodys[i] = cc.PhysicsBody:create()
			bodys[i]:setContactTestBitmask(-1)
			bodys[i]:addShape(shape)
			self.sprites[i]:setPhysicsBody(bodys[i])
		end
	end

	--self:getParent():addEventListener('onTouch',handler(self,self.onTouch))
	self:addNodeEventListener(cc.NODE_EVENT, function(event)
		if event.name == 'enter' then
			self:onEnter()
		end
	end)
end

function min_test:onTouch(event)
	print('receive a Touch event!',event.name)
end

function min_test:onEnter()
	print('min_test:onEnter')
	self:getParent():addEventListener('onTouch',handler(self,self.onTouch))
end

return min_test